package com.sys.platform.service.impl;

import com.sys.platform.common.utils.StringUtils;
import com.sys.platform.entity.Camera;
import com.sys.platform.entity.EntranceGuard;
import com.sys.platform.entity.EntranceGuardAccessRecord;
import com.sys.platform.mapper.CameraMapper;
import com.sys.platform.mapper.EntranceGuardAccessRecordMapper;
import com.sys.platform.mapper.EntranceGuardMapper;
import com.sys.platform.service.IEntranceGuardService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service
public class EntranceGuardServiceImpl implements IEntranceGuardService {

    @Autowired
    private ImageUrlServiceImpl imageUrlService;

    @Resource
    private EntranceGuardAccessRecordMapper entranceGuardAccessRecordMapper;

    @Autowired
    private EntranceGuardMapper entranceGuardMapper;

    @Autowired
    private CameraMapper cameraMapper;

    /**
     * 查询门禁访问记录列表
     *
     * @param accessRecord 门禁访问记录
     * @return 门禁人员管理集合
     */
    public List<EntranceGuard> selectEntranceGuardList(EntranceGuard accessRecord) {
        List<EntranceGuard> entranceGuardList = entranceGuardMapper.selectList(accessRecord);
        return entranceGuardList;
    }

    /**
     * 查询门禁访问记录
     *
     * @param accessRecord 门禁
     * @return
     */
    @Override
    public List<EntranceGuardAccessRecord> selectEntranceGuardAccessRecordList(EntranceGuardAccessRecord accessRecord) {
        List<EntranceGuardAccessRecord> entranceGuardList = entranceGuardAccessRecordMapper.selectList(accessRecord);
        entranceGuardList.stream().forEach(item -> {
            if (StringUtils.isNotEmpty(item.getPicUrl())) {
                item.setPicUrl(imageUrlService.getImageUrl(0) + item.getPicUrl().split("9000")[1]);
            }
            Camera camera = new Camera();
            camera.setCameraName(item.getRemark());
            List<Camera> cityCameraList = cameraMapper.select(camera);
            if (StringUtils.isNotEmpty(cityCameraList)) {
                item.setCameraCode(cityCameraList.get(0).getCameraCode());
            }
        });
        return entranceGuardList;
    }

}
